package com.boot.utils;

/**
 * 当前线程用户上下文，用于在请求过程中传递登录用户 ID
 */
public class UserContext {
    private static final ThreadLocal<Long> currentUserId = new ThreadLocal<>();

    public static void setCurrentUserId(Long userId) {
        if (userId == null) {
            clear();
        } else {
            currentUserId.set(userId);
        }
    }

    public static Long getCurrentUserId() {
        return currentUserId.get();
    }

    public static void clear() {
        currentUserId.remove();
    }
}
